<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>场馆搜索界面</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <!-- 引入Layui的CSS文件 -->
    <link rel="stylesheet" href="layui/css/layui.css" media="all">
    <!-- 引入Vue.js -->
    <script src="js/vue.js"></script>
    <!-- 引入jQuery -->
    <script src="js/jquery-3.6.0.min.js"></script>
    <!-- 引入Layui的JavaScript文件 -->
    <script src="layui/layui.js"></script>
</head>
<body>
<div id="app">
    <div class="layui-container">
        <div class="layui-row">
            <div class="layui-col-md12">
                <form class="layui-form" style="margin-top: 30px;">
                    <div class="layui-form-item layui-form-inline">
                        <div class="layui-input-inline">
                            <input type="text" v-model="keyword" placeholder="请输入场馆名称" autocomplete="off" class="layui-input">
                        </div>
                        <button type="button" @click="searchStadiums" class="layui-btn">搜索</button>
                    </div>
                </form>
            </div>
        </div>

        <!-- 搜索结果表格 -->
        <table class="layui-table" v-if="stadiums.length > 0">
            <colgroup>
                <col width="80">
                <col width="120">
                <col width="100">
                <col width="100">
                <col width="100">
                <col width="200">
                <col width="100">
            </colgroup>
            <thead>
                <tr>
                    <th>场馆ID</th>
                    <th>场馆名称</th>
                    <th>长度</th>
                    <th>宽度</th>
                    <th>高度</th>
                    <th>备注</th>
                    <th>负责人ID</th>
                </tr>
            </thead>
            <tbody>
                <tr v-for="stadium in stadiums" :key="stadium.stadiumId">
                    <td>{{ stadium.stadiumId }}</td>
                    <td>{{ stadium.stadiumName }}</td>
                    <td>{{ stadium.stadiumLength.toFixed(2) }}</td>
                    <td>{{ stadium.stadiumWidth.toFixed(2) }}</td>
                    <td>{{ stadium.stadiumHeight.toFixed(2) }}</td>
                    <td>{{ stadium.stadiumRemark }}</td>
                    <td>{{ stadium.userId }}</td>
                </tr>

            </tbody>
        </table>

        <!-- 无结果提示 -->
    
    </div>
</div>

<script>
    new Vue({
        el: '#app',
        data: {
            keyword: '',       // 搜索关键字
            stadiums: []       // 搜索结果
        },
        methods: {
            searchStadiums() {
                const url = "http://localhost:8080/stadium/serchByName";
                const params = { stadiumName: this.keyword };
        
                $.get(url, params, (response) => {
                    console.log(response);
                    if (response.code === 200) {
                        this.stadiums = response.data; // 确保正确赋值
                    } else {
                        this.stadiums = []; // 未找到数据时清空表格
                        layer.msg('未找到匹配的场馆信息，请重新输入。', { icon: 2 });
                    }
                }, "json").fail((error) => {
                    console.error('Error:', error);
                    layer.msg('查询失败，请稍后再试。', { icon: 2 });
                });
            }
        }

    });
</script>
</body>
</html>
